﻿using Microsoft.VisualStudio.TestTools.UITesting;

namespace CodedUITestExtensions
{
    /// <summary>
    /// Extensions for UITestControl.
    /// </summary>
    public static class UITestControlExtension
    {
        /// <summary>
        /// Searching control during a specified timeout.
        /// </summary>
        /// <param name="control">Control.</param>
        /// <param name="timeout">Search timeout.</param>
        /// <returns>Search result.</returns>
        public static bool TryFind(this UITestControl control, int timeout)
        {
            int startTimeout = Playback.PlaybackSettings.SearchTimeout;
            Playback.PlaybackSettings.SearchTimeout = timeout;
            bool result = control.TryFind();
            Playback.PlaybackSettings.SearchTimeout = startTimeout;
            return result;
        }
    }
}
